class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution(object):
    def removeZeroSumSublists(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        mut_head = ListNode(0, head)
        d = {}
        d[0] = mut_head
        now = 0
        node = mut_head.next
        while node:
            now += node.val
            if now in d:
                last_node = d[now].next
                d[now].next = node.next
                last_now = now
                while last_node != node:
                    last_now += last_node.val
                    d.pop(last_now)
                    last_node = last_node.next
            else:
                d[now] = node
            node = node.next
        return mut_head.next
